package com.ctshk.sapp.tour.controller;

import java.util.List;

import javax.validation.Valid;

import com.ctshk.common.exception.BusinessException;
import com.ctshk.rpc.tour.req.trip.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.tour.dto.SeriesTripDTO;
import com.ctshk.rpc.tour.dto.SeriesTripTouristTypeDTO;
import com.ctshk.rpc.tour.dto.TripBasicInformationDTO;
import com.ctshk.rpc.tour.dto.TripFileDTO;
import com.ctshk.rpc.tour.req.SeriesTripScheduleItineraryDayReq;
import com.ctshk.rpc.tour.req.TripListQueryReq;
import com.ctshk.rpc.tour.req.TripSupplementReq;
import com.ctshk.rpc.tour.service.ISeriesTripService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 系列团行程 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-12
 */
@Api(value = "新增行程--主表", tags = "新增行程--主表")
@RestController
@RequestMapping("/series/trip")
public class SeriesTripController extends BaseController {

    @DubboReference
    private ISeriesTripService iSeriesTripService;

    @ApiOperation(value = "查询行程-基本资料", notes = "查询行程-基本资料")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "查询行程-基本资料", operDesc = "查询行程-基本资料")
    @GetMapping("/basic/information/{id}")
    public Result<TripBasicInformationDTO> basicInformation(@PathVariable Long id) {
        return Result.success(iSeriesTripService.basicInformation(id));
    }


    @ApiOperation(value = "查询-行程信息", notes = "查询 -行程信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.ADD, operTitle = "查询-行程信息", operDesc = "查询-行程信息")
    @GetMapping("/itinerary/information/{id}")
    public Result<SeriesTripScheduleItineraryDayReq> tripItineraryInformation(@PathVariable Long id) {
        return Result.success(iSeriesTripService.tripItineraryInformation(id));
    }

    @ApiOperation(value = "查询-补充资料", notes = "查询-补充资料")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "查询-补充资料", operDesc = "查询-补充资料")
    @GetMapping("/supplement/{id}")
    public Result<TripSupplementReq> tripSupplement(@PathVariable Long id) {
        return Result.success(iSeriesTripService.tripSupplement(id));
    }


    @ApiOperation(value = "新增行程-补充资料", notes = "新增行程-补充资料")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.ADD, operTitle = "新增行程-补充资料", operDesc = "新增行程-补充资料")
    @PostMapping("/supplement")
    public Result supplement(@RequestBody @Valid TripSupplementReq tripSupplementReq) {
        iSeriesTripService.supplement(tripSupplementReq);
        return Result.success();
    }

    @ApiOperation(value = "查询行程列表", notes = "查询行程列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "查询行程列表", operDesc = "查询行程列表")
    @PostMapping("/trip/list")
    public Result<PageResponse<SeriesTripDTO>> tripList(@RequestBody @Valid TripListQueryReq tripListQueryReq) {
        return Result.success(iSeriesTripService.tripList(tripListQueryReq, getCurrentUser(getRequest())));
    }
    
    @ApiOperation(value = "CMS查询行程列表", notes = "CMS查询行程列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "CMS查询行程列表", operDesc = "CMS查询行程列表")
    @PostMapping("queryCmsTripList")
    public Result<PageResponse<SeriesTripDTO>> queryCmsTripList(@RequestBody @Valid TripListQueryReq tripListQueryReq) {
        return Result.success(iSeriesTripService.queryCmsTripList(tripListQueryReq));
    }

    @ApiOperation(value = "修改行程状态", notes = "修改行程状态")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.UPDATE, operTitle = "修改行程状态", operDesc = "修改行程状态")
    @PostMapping("/update/trip/status")
    public Result updateTripStatus(@RequestBody @Valid UpdateStatusReq updateStatusReq) {
        try {
            iSeriesTripService.updateTripStatus(updateStatusReq, getCurrentUser(getRequest()));
            return Result.success();
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "批量禁售/开售", notes = "批量禁售/开售")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.UPDATE, operTitle = "批量禁售/开售", operDesc = "批量禁售/开售")
    @PostMapping("/update/trip/schedule/status")
    public Result updateTripScheduleStatus(@RequestBody @Valid UpdateTripScheduleStatusReq updateTripStatusReq) {
        iSeriesTripService.updateTripScheduleStatus(updateTripStatusReq);
        return Result.success();
    }

    @ApiOperation(value = "文件上传", notes = "文件上传")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.ADD, operTitle = "文件上传", operDesc = "文件上传")
    @PostMapping("/add/trip/file")
    public Result addTripFile(@RequestBody @Valid AddTripFileReq addTripFileReq) {
        iSeriesTripService.addTripFile(addTripFileReq, getCurrentUser(getRequest()));
        return Result.success();
    }

    @ApiOperation(value = "行程--档案管理", notes = "行程--档案管理")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "行程--档案管理", operDesc = "行程--档案管理")
    @GetMapping("/trip/file/list/{id}")
    public Result<List<FileReq>> recordFileList(@PathVariable Long id) {
        return Result.success(iSeriesTripService.recordFileList(id));
    }

    @ApiOperation(value = "行程--查询旅客类型", notes = "行程--查询旅客类型")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "行程--查询旅客类型", operDesc = "行程--查询旅客类型")
    @GetMapping("/trip/tourist/type/{id}")
    public Result<List<SeriesTripTouristTypeDTO>> tripTouristType(@PathVariable Long id) {
        return Result.success(iSeriesTripService.tripTouristType(id));
    }

    @ApiOperation(value = "行程--查询线程列表（提供给团期）", notes = "行程--查询线程列表（提供给团期）")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "行程--查询线程列表（提供给团期）", operDesc = "行程--查询线程列表（提供给团期）")
    @PostMapping("/trip/schedule/list")
    public Result<List<SeriesTripDTO>> tripScheduleList(@RequestBody @Valid TripListQueryReq tripListQueryReq) {

        return Result.success(iSeriesTripService.tripScheduleList(tripListQueryReq, getCurrentUser()));
    }

    @ApiOperation(value = "行程审批", notes = "行程审批")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "行程审批", operDesc = "行程审批")
    @PostMapping("/trip/approval")
    public Result approval(@RequestBody @Valid TripApprovalReq tripApprovalReq) {
        iSeriesTripService.approval(tripApprovalReq, getCurrentUser(getRequest()));
        return Result.success();
    }

    @ApiOperation("旅行团行程码是否已存在")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.OTHER, operTitle = "旅行团详情", operDesc = "旅行团详情")
    @GetMapping("/isExistsTripCode/{tripCode}")
    public Result<Boolean> isExistsTripCode(@PathVariable String tripCode) {
		return iSeriesTripService.isExistsTripCode(tripCode);
	}
    
    @ApiOperation("设置当季热点")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.OTHER, operTitle = "设置当季热点", operDesc = "设置当季热点")
    @GetMapping("/changeHot/{tripId}")
    public Result<Void> changeHot(@PathVariable String tripId) {
    	return iSeriesTripService.changeHot(tripId, getCurrentUserId());	
	}
}